package contest1611;

import java.util.Arrays;
import java.util.Scanner;

public class C {
    static class Task implements Comparable<Task> {
        int start, end;

        @Override
        public int compareTo(Task that) {
            return this.end - that.end;
        }

        public Task(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    public static void main(String[] args) {
        while(cin.hasNext()){
            Task[] tasks = new Task[cin.nextInt()];
            for (int i = 0; i < tasks.length; i++) {
                tasks[i] = new Task(cin.nextInt(), cin.nextInt());
            }
            Arrays.sort(tasks);
            int end = 0;
            int cnt = 0;
            for (Task task : tasks) {
                if (task.start >= end) {
                    ++cnt;
                    end = task.end;
                }
            }
            System.out.println(cnt);
        }
        cin.close();
    }

    static Scanner cin = new Scanner(System.in);
}
